<template>
  <SearchTable ref="refSearch" :config="config" :columns="columns"
               :pagination="pagination" :loadData="loadData" >
  </SearchTable>
</template>

<script setup lang="ts" name="systemLog">

import {onActivated, ref} from "vue";
import {loadAuditLogPage, loadSystemLogPage} from "@/apis";
import SearchTable from "@/components/common/SearchTable.vue";

const refSearch = ref();

const loadData = async (params: any) => {
  if (params.logTime && params.logTime.length === 2) {
    params.startDate = params.logTime[0];
    params.endDate = params.logTime[1];
    delete params.logTime;
  }

  return await loadSystemLogPage({
    platformId: 'sso_manager_platform',
    ...params
  });
}

const searchItems = [
  {
    type: 'input',
    name: 'userName',
    label: '用户名称',
    size: 'default',
    placeholder: '请输入操作人名称',
    clearable: true,
  },
  {
    type: 'date-range',
    subType: 'datetimerange',
    name: 'logTime',
    label: '记录时间',
    size: 'default',
    placeholder: '请选择',
    placeholders: [
      '开始时间', '结束时间'
    ],
    clearable: true,
    format: 'YYYY/MM/DD HH:mm:ss',
    valFormat: 'YYYY-MM-DD HH:mm:ss',
  }
]

const tableAction = [{}
  // {type: 'success', name: 'export', label: '导出', icon: 'TopRight',}
]

const columns = ref([
  {
    id: 'id',
    name: '标识',
    hideCol: true,
    show: false,
  },
  {
    id: 'clientId',
    name: '客户标识',
    show: true,
  },
  {
    id: 'userName',
    name: '用户名称',
    show: true,
  },
  {
    id: 'actionType',
    name: '操作类型',
    show: true,
  },
  {
    id: 'actionStatus',
    name: '操作状态',
    show: true,
  },
  {
    id: 'actionTime',
    name: '操作时间',
    show: true,
  },
  {
    id: 'actionData',
    name: '操作数据',
    show: true,
  },
  {
    id: 'failInfo',
    name: '失败信息',
    show: true,
  },
])

const pagination = ref({
  current: 1,
  pageSize: 10,
  total: 0,
});

const config = ref({
  showSearch: true,
  search: searchItems,
  title: '日志列表',
  toolMode: '',
  setting: {
    showMoreSearch: false,
    showMoreButton: false,
    disableMoreButton: false,
    tableToolRound: '0',
    tableToolBackground: '',
  },
  layout: {
    buttonSize: 'default',
    actionButtonSize: 'default',
    inputSize: 'default',
  },
});

onActivated(() => {
  //refSearch.value?.refresh();
})

</script>

<style scoped>
.el-form-item-class .el-form-item__label {
  color: #C7C8CA;
  font-size: 12px;
}

</style>
